ax.baseURL = "http://likede2-admin.itheima.net/likede"
let clientToken = 0
//获取验证码
function getCodeImage() {
	clientToken = randomToken(16) //随机clientToken
	ax.GETBody(`/api/user-service/user/imageCode/${clientToken}`, {}, rel => {
		dq(".codeImage img").src = rel.request.responseURL
	})
}
//登录
function login(loginName, password, code, loginType) {
	ax.POSTBody(
		"/api/user-service/user/login",
		{ loginName, password, code, clientToken, loginType },
		({ data: { success, msg, userName } }) => {
			!success
				? Modal.toast(msg, "", "rgba(255,25,0,0.5)")
				: (Modal.toast(msg, "", "rgba(68, 255, 64, 0.5)"),
				  local.set("username", userName),
				  local.set("clientToken", clientToken),
				  active(),
				  setTimeout(() => {
						location.href = "index.html"
				  }, 2000))
		},
		err => Modal.toast("登陆失败", "center", "rgba(255,25,0,0.5)")
	)
}
